package com.edgclub.edg.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RelativeLayout;

import com.edgclub.edg.R;
import com.edgclub.edg.fragment.MeFragment;
import com.edgclub.edg.model.User;

import java.util.ArrayList;

public class MineActivity extends GzBaseTooolBarActivity implements View.OnClickListener {

    private ViewPager mViewpager2;
    private MyPagerAdapter myPagerAdapter;
    private ArrayList<Fragment> fragmentList=new ArrayList<>();;
    private String titlestr="";
    private RelativeLayout main_back;
    @Override
    public int getContentView() {
        return R.layout.activity_action;
    }

    @Override
    public void setTitleBarView() {
        setStatusBarHeight(true);
    }

    @Override
    public void initView() {
        mViewpager2 = (ViewPager) findViewById(R.id.viewpager2);
        main_back = (RelativeLayout) findViewById(R.id.main_back);
        main_back.setOnClickListener(this);
    }

    @Override
    public void initData() {
        myPagerAdapter=new MyPagerAdapter(getSupportFragmentManager());
        fragmentList.add(MeFragment.newInstance());
        myPagerAdapter.setFragmentList(fragmentList);
        mViewpager2.setAdapter(myPagerAdapter);
        mViewpager2.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.main_back:
                Intent intent3=new Intent(MineActivity.this,GzMainActivity.class);
                setResult(RESULT_OK, intent3);
                finish();
                break;

        }
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        try {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                Intent intent3=new Intent(MineActivity.this,GzMainActivity.class);
                setResult(RESULT_OK, intent3);
                finish();
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        return super.onKeyDown(keyCode, event);
    }
    public class MyPagerAdapter extends FragmentPagerAdapter {

        ArrayList<Fragment> fragmentList;

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return "";
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }


        public void setFragmentList(ArrayList<Fragment> fragmentList) {
            this.fragmentList = fragmentList;
        }
    }
}